package com.ssm.controller;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ssm.pojo.Type;
import com.ssm.service.TypeService;


@Controller
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;

    @RequestMapping("/findAll")
    public String findALL(Model model) {
        List<Type> types = typeService.findALL();
        model.addAttribute("types", types);
        return "/guan/showType";
    }

    @RequestMapping("/toAddType")
    public String toAddYong() {
        return "guan/addType";
    }

    @RequestMapping("/add")
    public String add(String tname) {
        typeService.add(tname);
        return "redirect:/type/findAll";
    }

    @RequestMapping("/findBySname")
    public String findBySname(String tname, Model model) {
        List<Type> types = typeService.findBySname(tname);
        model.addAttribute("types", types);
        return "/guan/showType";
    }

    @RequestMapping("/findById")
    public String findById(long id, Model model) {
        Type type = typeService.findById(id);
        model.addAttribute("tyoe", type);
        return "/guan/updateType";
    }

    @RequestMapping("/modify")
    public String modify(long id, String tname) {
        typeService.modify(id, tname);
        return "redirect:/type/findAll";
    }

}
